home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: lafn.org!an234
- From: an234@lafn.org (Andres Lessing)
- Subject: Re: Finding a prime number
- X-Nntp-Posting-Host: lafn.org
- Message-ID: <1996Feb14.070305.19468@lafn.org>
- Sender: news@lafn.org
- Reply-To: an234@lafn.org (Andres Lessing)
- Organization: The Los Angeles Free-Net
- References: <DMpuHt.3yL@cwi.nl> <4fl2tl$ln6@ns2.emirates.net.ae> <4fnnfuINNib7@keats.ugrad.cs.ubc.ca> <4fp2kt$pks@oban.cc.ic.ac.uk
- Date: Wed, 14 Feb 1996 07:03:05 GMT
-
-
- In a previous article, dik@cwi.nl (Dik T. Winter) says:
-
- >In article <4fp2kt$pks@oban.cc.ic.ac.uk> a.kruczkowski@ic.ac.uk (Alex Kruczkowski) writes:
- > > Any comments or am I way off here? ;-)
- >
- >Way off I think. There is no repeating pattern in the list of prime
- >numbers.
- >--
- >dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
- >home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
- >
- Ok... Here is some code
-
- #include <stdio.h>
- #include <conio.h>
-
- int is_prime(int n)
- //return 0 if not prime
- //return 1 if prime
- {
- int i,temp=0;
- for(i=2; i==n-1, n%i!=0; i++)
- {
- }
- /* If i==n or n ==1 then n is prime */
- if (i==n || n==1) temp = 1;
- return(temp);
- }
-
- I think this works pretty well. I however don't know how fast it is..
-
-
- Hope it helps
- --
- Hofstadter's Law: | o__
- It always takes longer than you expect, even | _.</)_
- when you take Hofstadter's Law into account. | (_) \(_)
- " Godel Escher Bach" | Andres, an234@lafn.org
-